package game.source.ships;

import game.source.gui.ship.CallBackShipInterface;
import game.source.manager.ShowInterface;
import game.source.physics.PhysicsObjectInterface;
import game.source.shot.GuiShotInterface.Level;
import game.source.sound.AudioBuffer;
import game.source.sound.WavePlayer;
import game.source.util.TimerControlInterface;

import java.awt.Point;

public abstract class Ship implements CallBackShipInterface,PhysicsObjectInterface,ShowInterface,TimerControlInterface{
	protected 	GuiShipInterface gui;		//CallBack para o visual do jogo
	protected 	GameInterface game;			//CallBack para a fase do jogo
	protected int helthPoints;				//Pontuação de vida
	private Point position;					//Posição da nave na tela
	private double velx;					//Velocidade da nave em px/s no x
	private double vely;					//Velocidade da nave em px/s no y
	private static AudioBuffer explosionBuffer;
	private WavePlayer eplosion;

	static{
		Ship.explosionBuffer = new AudioBuffer("/sounds/Explosion.wav");
	}

	public Ship(int helthPoints,int shildPoints,Point position,GuiShipInterface gui,GameInterface game,double velx,double vely){
		this.gui			= gui;
		this.game			= game;
		this.helthPoints	= helthPoints;
		this.position		= position;
		this.velx			= velx;
		this.vely			= vely;
		this.eplosion		= new WavePlayer(Ship.explosionBuffer);	
		this.gui.setShip(this);
		this.gui.setVel(velx, vely);
		this.gui.start(this.position);
	}
	public GuiShipInterface getGui(){
		return this.gui;
	}
	public int getHelthPoints(){
		return this.helthPoints;
	}
	public void setHelthPoints(int helthPoints){
		this.helthPoints = helthPoints;
	}
	public int getPosX(){
		return this.position.x;
	}
	public int getPosY(){
		return this.position.y;
	}
	public double getVelx(){
		return this.velx;
	}
	public double getVely(){
		return this.vely;
	}
	public Point getPosition(){
		return position;
	}
	@Override
	public void reciveFire(Level level){
		this.eplosion.play();
	}
	@Override
	public void setPosition(Point position){
		this.position.x = position.x;
		this.position.y = position.y;
	}
	public void move(Point position){
		this.gui.move(position);
	}

	@Override
	public void show(long time){
		this.gui.show(time);
	}

	@Override
	public int getX0() {
		return this.gui.getX0();
	}
	@Override
	public int getY0() {
		return this.gui.getY0();
	}
	@Override
	public int getWidth() {
		return this.gui.getWidth();
	}
	@Override
	public int getHeight() {
		return this.gui.getHeight();
	}
	@Override
	public byte getPixelAlpha(int x, int y) {
		return this.gui.getPixelAlpha(x, y);
	}
	@Override
	public void start() {
		this.gui.start();		
	}
	@Override
	public void play() {
		this.gui.play();		
	}
	@Override
	public void pause() {
		this.gui.pause();
	}
	@Override
	public void end() {
		this.eplosion.end();
		this.gui.pause();
	}
	@Override
	public boolean isPaused() {
		return this.gui.isPaused();		
	}
}
